'''
    定义字符串变量
        字符串变量 = "字符..."
        字符串变量 = '字符...'
    他说："python很简单"

    *长度len(字符串长度)
    *每个字符都有下标 从0开始
    *切片操作
        变量[起始位置：结束位置：步长]
'''

str1 = '他说："python很简单"'
str2 = "他的外号叫'小猪'"
str3 = '''

'''
print(len(str1))
print(len(str2))
print(len(str3))

print(str2[6],str2[7])
print(str1[4:-1])
print(str2[6:8])
print(str1[:len(str1):2])
print(str1[::2])
print(str1[3::])
print(str1[::-1])


#查找字符串
# find index count
print(str1.find('python')) #存在返回下标
print(str1.find('python1')) # 不存在返回-1

print(str1.index('python'))
# print(str1.index('python2')) #不存在报错

print(str1.count('p'))

# replace
str4 = "祖国大好河山"

str5= str4.replace("河山","山河")
print(str4)
print(str5)

# split 分割

str5 = "小黄,小白,小刘"
names = str5.split(",")
print(names)

# 开始 结束
print(str4.startswith("祖国"))
print(str4.endswith("河山"))

keyword = "  铅   笔  "
print(keyword.strip()) #去除两边空格
print(keyword.lstrip()) #去除左边空格
print(keyword.rstrip()) # 去除右边空格
print(keyword.replace(" ", "")) #将空格替换为空

astr = "ABC哎哎哎"
print(str5.isalpha()) #字母汉字为真
print(astr.isalpha())
print(astr.isdigit()) # 数字为真
print(astr.isalnum()) # 字母汉字数字为真

# 输入一段数字和字母组合，判断数字和字母各有多少个
numCount = 0
charCount = 0
strX = input("请输入一个字符串")
for x in strX:
    if x.isdigit():
        numCount += 1
    if x.isalpha():
        charCount += 1
print("数字出现的次数为{}，字母出现的次数为{}".format(numCount, charCount))

strY = "aaas4d45sa4a45a454sa54a54d544a45d5"
i = strY.find("a")
while i >= 0 :
    print(i)
    i = strY.find("a", i+1)
